package com.server;

import java.io.IOException;
import java.sql.SQLException;

import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Helper.*;

public class DisplayPassServlet extends CustomerServlet
{
	private static final long serialVersionUID = 1L;
	private final String className = "View Pass Servlet: ";

	@Override
	//@requires HttpServletRequest !=NULL,  HttpServletResponse !=NULL ;
    //@assignable PassInfo, SeatInfo, username, resID;
	//@signals_only RuntimeException, IOException,ServletException;
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
	{
		ConnectDB();
		String username = req.getParameter("username");
		String resID = req.getParameter("r1");
		String imgpath = null;
			
		PassInfo passInfo = new PassInfo();
		SeatInfo seatInfo = new SeatInfo();
				
		try //get the seating info and display
		{
			ReservationHelper.Setup(connection, username);
			SeatHelper.Setup(connection);
			passInfo = ReservationHelper.GetSelectedPass(resID);
			seatInfo = SeatHelper.GetSelectedSeat(passInfo.seat, passInfo.flightID);
			
			if (passInfo.airline.equals("Air Canada"))
			{
				imgpath = "icon/acpass.png";
			}
			else
			{
				imgpath = "icon/chinapass.png";
			}
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
		
		
		req.setAttribute("passInfo", passInfo);
		req.setAttribute("seatInfo", seatInfo);
		req.setAttribute("username", username);
		req.setAttribute("imgpath", imgpath);
		req.getRequestDispatcher("reservation/displayPass.jsp").forward(req, resp);	
		
		
		
		
	}

}

